<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of preordain_model
 *
 * @author Administrator
 */
class System_model extends MY_Model{
    const DB = 'system';
    /*
     * 取得表内内容
     */
    public function lists($where = array(),$select = '*')
    {
        foreach($where as $id=>$item){
            $this->db->where($id,$item);	
		}
		$this->db->select($select);
		$this->db->from(self::DB);
		$query = $this->db->get();
		return $query->result();
    }

	/*
	 * 写入内容
	 * @param string key 需要写入的数据
	 * @param string value 值
	 * @param string exp 说明
	 */
	public function add($key,$value,$exp="")
	{
		$t = $this->lists(array('title'=>$key),'count(id) as count');
		if($t[0]->count>0)
		{
			$this->db->where('title',$key);
			$this->db->update(self::DB,array('content'=>$value));
		}
		else
		{
			$this->db->insert(self::DB,array('id'=>'','title'=>$key,'content'=>$value,'exp'=>$exp));
		}
		$this->cache->memcached->delete('system_data');
	}
}